#ifndef HQCUSTOMPLOT_H
#define HQCUSTOMPLOT_H

#include "qcustomplot.h"

#define MARKERNUM 10

/*! \file */

class QCPItemMaker : public QCPItemTracer
{

public:

    QCPItemMaker(QCustomPlot *parentPlot, QString text);
    virtual ~QCPItemMaker();
    QString GetText() const {return this->text;}
    bool GetDeltaEn() const {return this->isDelta;}
    int GetDeltarRef() const {return this->m_refMkr;}
    void SetDeltaEn(bool en);
    void SetDeltaRef(int ref);

    // reimplemented virtual methods:
    virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
    void setGraph(QCPGraph *graph);
protected:
    // reimplemented virtual methods:
    virtual void draw(QCPPainter *painter);

private:
    QString text;
    bool isDelta;
    int m_refMkr;
};

class HQCustomPlot : public QCustomPlot
{

public:

    HQCustomPlot(QWidget *parent = 0);
    virtual ~HQCustomPlot();

    // marker interface:
    QCPItemMaker *marker(int index=0) const;
    bool addMarker(int index, int mkrToTrace=0, bool delta=false, int ref=0);
    bool removeMarker(int index);
    int clearMarker();
    Q_SLOT void replot();
    bool GetMarkerTextEn() const { return mMarkerTextEn; }
    void SetMarkerTextEn(bool enable);

protected:
    //marker:
    QCPItemMaker *mMarkers[MARKERNUM];
    QCPItemText *markerText;
    int activeMarkerIdx;
    //mouse event
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    void updateMarkerText(bool enable);
private:
    bool mMarkerTextEn;
};

#endif // MYQCUSTOMPLOT_H
